﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace MuggleTactics
{
    class Unit : Piece
    {
        // Unit Traits
        private bool isPlayer;
        private int hitPoints;
        private int magic;
        private int defense;
        private int magicPoints;
        private List<Spell> spells;        
        private List<Item> items;
        private int timeSinceLastFrame = 0;

        public Unit(Game1 game, Texture2D textureImage, Vector2 position,
                    Point currentFrame, Point frameSize, Point sheetSize,
                    string name, int hp, int magic, int defense, int magicPoints, 
                    bool isPlayer, List<Spell> spells, List<Item> items)
                    : base(game, textureImage, position, currentFrame, frameSize, sheetSize)
        {
 
            this.setName(name);
            this.setHP(hp);
            this.setMagic(magic);
            this.setDefense(defense);
            this.setMagicPoints(magicPoints);
            this.setIsPlayer(isPlayer);
            this.setSpells(spells);
            this.setItems(items);
        }

        // Making the Setters
        #region setters
        public void setIsPlayer(bool isPlayer) { this.isPlayer = isPlayer; }
        public void setHP(int hitPoints) { this.hitPoints = hitPoints; }
        public void setMagic(int magic) { this.magic = magic; }
        public void setDefense(int defense) { this.defense = defense; }
        public void setMagicPoints(int magicPoints) { this.magicPoints = magicPoints; }

        public void setSpells(List<Spell> spells)
        {
            this.spells = spells;
        }

        public void setItems(List<Item> items)
        {
            this.items = items;
        }
        #endregion

        // Making the Getters
        #region getters
        public bool getIsPlayer() { return this.isPlayer; }
        public int getHitPoints() { return this.hitPoints; }
        public int getMagic() { return this.magic; }
        public int getDefense() { return this.defense; }
        public int getMagicPoints() { return this.magicPoints; }
       

        public Spell getSingleSpell(int singleSpell)
        {
            return spells[singleSpell-1];
        }

        public Item getSingleItem(int singleItem)
        {
            return items[singleItem];
        }

        public List<Spell> getSpells()
        {
            return spells;
        }

        public List<Item> getItems()
        {
            return items;
        }

        public List<String> getSpellNames()
        {
            List<String> spellNames = new List<String>();

            foreach (Spell spell in spells)
            {
                spellNames.Add(spell.getName());
            }

            return spellNames;
        }

        public List<String> getItemNames()
        {
            List<String> itemNames = new List<String>();

            foreach (Item item in items)
            {
                itemNames.Add(item.getName());
            }

            return itemNames;
        }
        #endregion

        public override void Update(GameTime gameTime, Rectangle clientBounds)
        {
            timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;

            if (timeSinceLastFrame > milliSecondsPerFrame)
            {
                timeSinceLastFrame = 0;
                currentFrame.X++;
                if (currentFrame.X >= sheetSize.X)
                    currentFrame.X = 0;
            }

            base.Update(gameTime, clientBounds);
        }

        public void modifyStat(StatsHelper.Stat stat, int value)
        {
            switch (stat)
            {
                case StatsHelper.Stat.hitPoints:
                    hitPoints += value;
                    if (hitPoints <= 0)
                    {
                        die();
                    }
                    break;
                case StatsHelper.Stat.magicPoints:
                    magicPoints += value;
                    break;
                default:
                    break;
            }
        }
        public void die()
        {
           
        }
    }
}